Re: [SQL] ' escape - Mailing list pgsql-sql

From Herouth Maoz
Subject Re: [SQL] ' escape
Date
Msg-id l0311070cb291ab8e015a@[147.233.159.109]
Whole thread Raw
In response to ' escape  (Fabio Mancinelli <mancinel@univaq.it>)
Responses Re: [SQL] ' escape
List pgsql-sql
At 17:31 +0200 on 7/12/98, Fabio Mancinelli wrote:


> I have a question. When I create a table I cannot use any escape to put a
> ' character in the default field definition.
>
> CREATE TABLE Test (name varchar(128) default 'Something with '' into');
>
> Fails. I've tried also other alternatives :
> default "Something with ' into"
> default "Something with '' into"
> default 'Something with \' into'
> default 'Something with \27 into'
> default 'Something with \0x27 into'
>
> Everything fails.

Interesting bug.

As a workaround, if you really need that default value, define a simple SQL
function which returns it:

testing=> CREATE FUNCTION specialValue() RETURNS varchar
testing-> AS 'SELECT ''a value with '''' in it''::varchar'
testing-> LANGUAGE 'sql';
CREATE
testing=> SELECT specialValue();
specialvalue
--------------------
a value with ' in it
(1 row)

Now define your table. Here is an example:

testing=> CREATE TABLE test6 (
testing->   id int,
testing->   name varchar(128) DEFAULT specialValue()
testing-> );
CREATE
testing=> INSERT INTO test6 (id) values (1);
INSERT 932640 1
testing=> SELECT * FROM test6;
id|name
--+--------------------
 1|a value with ' in it
(1 row)

Herouth

--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma



pgsql-sql by date:

Previous
From: Fabio Mancinelli
Date:
Subject: ' escape
Next
From: Sascha Schumann
Date:
Subject: Re: [SQL] Odd characters in inserted data...